package com.kzj.mls.recyclerCard.cardView;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.kzj.mls.R;
import com.kzj.mls.recyclerCard.basic.CardItemView;
import com.kzj.mls.recyclerCard.card.other.EditAddressCard;

/**
 * Created by xyg on 2015/10/26.
 */
public class EditAddressCardView extends CardItemView<EditAddressCard> {

    private Context context;
    private EditText editText_address;
    private LinearLayout linearlayout_delete;
    public EditAddressCardView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public EditAddressCardView(Context context) {
        super(context);
        this.context = context;
    }

    public EditAddressCardView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
    }

    @Override
    public void build(final EditAddressCard card) {
        super.build(card);
        editText_address = (EditText) findViewById(R.id.editText_address);
        linearlayout_delete = (LinearLayout) findViewById(R.id.linearlayout_delete);
        if (card.isShowDelete()){
            linearlayout_delete.setVisibility(VISIBLE);
        }else{
            linearlayout_delete.setVisibility(GONE);
        }
        linearlayout_delete.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                card.getOnNormalButtonPressedListener().onButtonPressedListener(v,card);
            }
        });
        if (card.getAddressBean() != null) {
            editText_address.setText(card.getAddressBean().getAddress());
        } else {

        }
        editText_address.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (card.getAddressBean() != null) {
                    card.getAddressBean().setAddress(s.toString());
                }
                card.setAddress(s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }
}
